//
//  ViewModel.swift
//  颖姐姐
//
//  Created by wu on 2017/6/22.
//  Copyright © 2017年 wu. All rights reserved.
//

import Foundation

class ViewModel {
    
    
    var array = [Model]()
    
    /// 请求方法
    ///
    /// - Parameter complete: 闭包回调，通知通知控制器数据已准备完成
    func loadData(page:Int = 1,complete:@escaping (_ finish:Bool)->()) {
        
        /// 请求参数
//        NetworkingManager.shared.request(URLString: <#T##String#>, parameter: <#T##[String : AnyObject]?#>, finish: <#T##(AnyObject?, Bool) -> ()#>)
        
        let parames = ["lat": "22.6046004324",
                       "lng": "114.1567003731",
                       "page":page] as [String : AnyObject]
        
        
        AlamofireManager.shared.loadDic(url: "https://www.uvein.cn/api/v2/service/getAllService", method: .POST, parameters: parames ) { (json, isSuccess) in
            if isSuccess {
                
                
//                guard let data = try? JSONSerialization.data(withJSONObject: json ?? "", options: [.prettyPrinted]) else{
//                    complete(false)
//                    return
//                }
//
//                (data as NSData).write(toFile: "/Users/wu/Desktop/index.json", atomically: true)
                
                
                guard let result = json?["data"] as? [[String:AnyObject]] else{
                    complete(false)
                    return
                }
                
                for dic in result{
                    self.array.append(Model(dic: dic))
                }
                complete(true)
                
            
            }else{
                complete(false)
            
            }
        }
  
        
    }
}
